package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Sign;
import com.ruoyi.system.service.ISignService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 生命体征Controller
 * 
 * @author 503
 * @date 2021-05-04
 */
@Controller
@RequestMapping("/system/sign")
public class SignController extends BaseController
{
    private String prefix = "system/sign";

    @Autowired
    private ISignService signService;

    @RequiresPermissions("system:sign:view")
    @GetMapping()
    public String sign()
    {
        return prefix + "/sign";
    }

    /**
     * 查询生命体征列表
     */
    @RequiresPermissions("system:sign:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Sign sign)
    {
        startPage();
        List<Sign> list = signService.selectSignList(sign);
        return getDataTable(list);
    }

    /**
     * 导出生命体征列表
     */
    @RequiresPermissions("system:sign:export")
    @Log(title = "生命体征", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Sign sign)
    {
        List<Sign> list = signService.selectSignList(sign);
        ExcelUtil<Sign> util = new ExcelUtil<Sign>(Sign.class);
        return util.exportExcel(list, "生命体征数据");
    }

    /**
     * 新增生命体征
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存生命体征
     */
    @RequiresPermissions("system:sign:add")
    @Log(title = "生命体征", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Sign sign)
    {
        return toAjax(signService.insertSign(sign));
    }

    /**
     * 修改生命体征
     */
    @GetMapping("/edit/{signId}")
    public String edit(@PathVariable("signId") Long signId, ModelMap mmap)
    {
        Sign sign = signService.selectSignById(signId);
        mmap.put("sign", sign);
        return prefix + "/edit";
    }

    /**
     * 修改保存生命体征
     */
    @RequiresPermissions("system:sign:edit")
    @Log(title = "生命体征", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Sign sign)
    {
        return toAjax(signService.updateSign(sign));
    }

    /**
     * 删除生命体征
     */
    @RequiresPermissions("system:sign:remove")
    @Log(title = "生命体征", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(signService.deleteSignByIds(ids));
    }
}
